
    let uploadFun = function(name){
        let objImg = $("#"+name+"-img");
        let objInput = $("#"+name);
        let objUpload = $("#"+name+"-upload");
        let objImgShow = $("#"+name+"-show");
        let objDel = $("#"+name+"-del");

        upload.render({
            elem: objUpload,
            url: '/admin/api/upload',
            accept:'images',
            acceptMime: 'image/*',
            field:'photo',
            before: function(){
                layer.load(1);
            },
            done: function(res){
                layer.closeAll('loading');
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败',{icon:2});
                }else{
                    objInput.val(res.data.url);
                    objImg.attr('src',res.data.url);
                    isImgNull();
                    return layer.msg('上传完成',{icon:1});
                }
            }
        });

        objDel.click(function () {
            deleted();
        });

        objImg.click(function () {
            let url = $(this).attr('src');
            if (url === '') {
                return false;
            }
            let json = {
                "title": "图片查看",
                "id": 1,
                "start": 0,
                "data": [
                    {
                        "alt": "查看图片",
                        "pid": '1',
                        "src": url,
                        "thumb": url
                    }
                ]
            };
            layer.photos({
                photos: json,
                anim: 5
            });
        });

        let deleted = function(){
            objInput.val('');
            objImg.attr('src','');
            isImgNull();
        };

        /**
         * 判断是否显示上传按钮
         */
        let isImgNull = function () {
            let data = objInput.val();
            if (typeof(data) === undefined ||  data === '') {
                objImgShow.hide();
                objUpload.show();
            }else{
                objUpload.hide();
                objImgShow.show();
            }
        };

        isImgNull();
    };
